package com.ruoyi.warning.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.warning.domain.entity.Mempool;
import com.ruoyi.warning.mapper.MempoolsMapper;
import com.ruoyi.warning.service.IMempoolsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenhc
 * @since 2025-03-25
 */
@Service
public class MempoolsServiceImpl extends ServiceImpl<MempoolsMapper, Mempool> implements IMempoolsService {

    @Override
    public Integer getMempoolById(Integer deviceId) {
        LambdaQueryWrapper<Mempool> wrapper = new QueryWrapper<Mempool>().lambda()
                .eq(Mempool::getDeviceId, deviceId);
        List<Mempool> list = this.list(wrapper);
        if(list.size() == 0){
            return null;
        }
        if(list.size() == 1){
            return list.get(0).getMempoolPerc();
        }
        wrapper = new QueryWrapper<Mempool>().lambda()
                .eq(Mempool::getDeviceId, deviceId)
                .eq(Mempool::getMempoolDescr, "Physical memory");
        list = this.list(wrapper);
        if(list.size() == 0){
            return null;
        }
        return list.get(0).getMempoolPerc();
    }
}
